var qouta_roles="医保";
var planYear;
$("#sdate").datetimepicker({
   format: "yyyy-mm",
   autoclose: true,
   todayBtn: true,
   minView: 3,
   startView:3,
   language: 'zh-CN'
});
$("#edate").datetimepicker({
   format: "yyyy-mm",
   autoclose: true,
   todayBtn: true,
   minView: 3,
   startView:3,
   language: 'zh-CN'
});
var paramTable;

$(function(){
	$("#planYear").datetimepicker({
		   format: "yyyy",
		   autoclose: true,
		   todayBtn: true,
		   minView: 4,
		   startView:4,
		   language: 'zh-CN'
		});
	qouta_roles=$("#roles").html()
	//根据角色删除下拉框的医保指标选项
	if(qouta_roles=="医政"){
		$("#"+tabId+" #paramQuotaCheck").find("option").each(function(i,n){
			if($(this).attr("value").indexOf("HC")==0){
				$(this).remove();
			}
		})
	}
	$('#processId').fadeOut();
	
	//获取最新日期
	$.ajax({
		url:contextPath + "/DrgsIndexCal/getLatestDate.dhc",
		async:false,
		type:"GET",
		dataType:"json",
		success:function(data){
			var latestDate = data.data
			if(latestDate){
				var latestMonth = latestDate.substr(0,7);
				$('#'+tabId+' #sdate').val(latestMonth);
				$('#'+tabId+' #edate').val(latestMonth);
			}else{
				$('#'+tabId+' #sdate').val(GetDateStr(0,'m'));
				$('#'+tabId+' #edate').val(GetDateStr(0,'m'));
			}
		}
	})
	//更新后台测算年份变量
	$("#"+tabId+" #planYear").change(function(){
		planYear=$(this).val();
		$.ajax({
			url:contextPath + "/ForeCast/changeYear.dhc",
			async:false,
			type:"GET",
			dataType:"json",
			data: {year: planYear},
			success:function(data){}
		});
		$("#"+tabId+" #search_png").click();
	})
	//点击查询预算数据
	$("#"+tabId+" #search_png").click(function(){
		
		var dateFrom = $("#"+tabId+" #sdate").val();
		var dateTo = $("#"+tabId+" #edate").val();
		//获得测算年份,默认去预算数据的下一年
		if($("#"+tabId+" #planYear").val()==undefined){
			planYear=Number(dateTo.substring(0, 4))+1;
			$("#"+tabId+" #planYear").val(Number(dateTo.substring(0, 4))+1);
		}
	//	$("#"+tabId+" #planYear").change();
		$("#"+tabId+" #date-from").html(dateFrom);
		$("#"+tabId+" #date-to").html(dateTo);
		//全院预算数据
		$.post(contextPath+"/DrgsIndexCal/indexCal.dhc", {
			'dateFrom':dateFrom,
			'dateTo':dateTo,
			'quotaCode':"ForeCast",
			'monitorType':"hosp",
			'msCode':"std_inner",
			'compareType':"std",
			'msCode': "std_inner",
			'gType': "1"
		}).done(function(result){
			//科室组预算数据及标杆
			$.post(contextPath+"/DrgsIndexCal/indexCal.dhc", {
				'dateFrom':dateFrom,
				'dateTo':dateTo,
				'quotaCode':"ForeCast",
				'monitorType':"depGroup",
				'compareType':"std",
				'msCode': "std_inner",
				'msCode':"std_inner",
				'gType': "1"
			}).done(function(result_1){
				var data = [];
				var hospData={};
				if(result.data && result.data.length>0){
					hospData = result.data[0];
					data.push(hospData);
				}
				if(result_1.data && result_1.data.length>0){
					data = data.concat(result_1.data);
				}
				var columns = [ 
			                     { "data": 'ddesc1', 
			                       "render": function(obj, type, full) {
			                    	   var ddesc = full.ddesc;
			                    	   if(ddesc=="全院"){
			                    		   return ddesc;
			                    	   }
			                    	   return "<a href=\"javascript:goToDepParam('"+full.ccode+"', '"+full.ddesc+"')\">"+full.ddesc+"</a>";
			                       }	 
			                     },
			                     { "data": 'TotalCaseCnt'},
			                     { "data": 'HCTotalCaseCnt'},
			                     { "data": 'HCTotalFund', 
				                       "render": function(obj, type, full) {
				                    	   return formatNumber(full.HCTotalFund/10000,3) ;
				                       }
			                     },
			                     { "data": 'AvgDays'},
			                     { "data": 'AvgDayscc'},
			                     { "data": 'AvgFee'},
			                     { "data": 'AvgFeecc'},
			                     { "data": 'HCAvgFee'},
			                     { "data": 'HCAvgFeecc'},
			                     { "data": 'AvgDrugFee'},
			                     { "data": 'AvgDrugFeecc'},
			                     { "data": 'HCAvgDrugFee'},
			                     { "data": 'HCAvgDrugFeecc'},
			                     { "data": 'AvgDrugMateFee'},
			                     { "data": 'AvgDrugMateFeecc'},
			                     { "data": 'HCAvgDrugMateFee'},
			                     { "data": 'HCAvgDrugMateFeecc'}
			                 ];
				
				var paramDatatable = {lengthChange:false, info:false, searching:false, order:[[ 1, "desc" ]]};
				if(qouta_roles!="医保"){
					paramDatatable.columnDefs=[{
						 "visible": false,
						  "targets": [2,3,8,9,12,13,16,17]
			         }]
				}
				
				$("#"+tabId+" #foredata-table").dataTableBasic(columns, data, paramDatatable);
				
				$("#"+tabId+" #hospAvgDays tr:eq(3)").find("td").eq(0).html(hospData.AvgDays);
				$("#"+tabId+" #hospAvgFee tr:eq(3)").find("td").eq(0).html(hospData.AvgFee);
				$("#"+tabId+" #hospHCTotalFund tr:eq(3)").find("td").eq(0).html(hospData.HCTotalFund);
				$("#"+tabId+" #hospDrugFee tr:eq(3)").find("td").eq(0).html(hospData.AvgDrugFee);
				$("#"+tabId+" #hospHCAvgFee tr:eq(3)").find("td").eq(0).html(hospData.HCAvgFee);
				$("#"+tabId+" #hospHCDrugFee tr:eq(3)").find("td").eq(0).html(hospData.HCAvgDrugFee);
				$("#"+tabId+" #hospTotalCaseCnt tr:eq(3)").find("td").eq(0).html(hospData.TotalCaseCnt);
				$("#"+tabId+" #hospHCCaseCnt tr:eq(3)").find("td").eq(0).html(hospData.HCTotalCaseCnt);
				$("#"+tabId+" #hospTotalCaseCnt tr:eq(3)").find("td").eq(0).html(hospData.TotalCaseCnt);
				$("#"+tabId+" #hospHCCaseCnt tr:eq(3)").find("td").eq(0).html(hospData.HCTotalCaseCnt);
				$("#"+tabId+" #hospTimeEff tr:eq(3)").find("td").eq(0).html(hospData.TimeEff);
				$("#"+tabId+" #hospFeeEff tr:eq(3)").find("td").eq(0).html(hospData.FeeEff);
				$("#"+tabId+" #hospDrugMateFee tr:eq(3)").find("td").eq(0).html(hospData.AvgDrugMateFee);
				$("#"+tabId+" #hospHCDrugMateFee tr:eq(3)").find("td").eq(0).html(hospData.HCAvgDrugMateFee);
				getLastResult();
			});
		});
		//获取上次保存的调整参数
		$.post(contextPath+ "/ForeCast/findDepGroupForeCast.dhc",{
			'dateFrom' : dateFrom,
			'dateTo' : dateTo,
			'roleName':qouta_roles,
			'type2': planYear
		}).done(function(result){
			var columns = [ 
                     	 { "data": 'depGroupDesc1',
	                       "render": function(obj, type, full) {
	                    	   return "<input type='checkbox' />  <a href=\"javascript:goToDepParam('"+full.depGroupCode+"', '"+full.depGroupDesc+"')\">"+full.depGroupDesc+"</a>";
	                       }
	                     },
	                     { "data": 'totalCaseCnt'},
 	                     { "data": "AvgDaysL1",
 	                       "render": function(obj, type, full) {
 	                    	   	 var avgDaysL = full.AvgDaysL?full.AvgDaysL:0;
  	                             return "<input id='"+full.depGroupCode+"_AvgDaysL' type='text' style='width:50px' value='"+avgDaysL+"'></input>";
  	                         }
   	                     },
 	                     { "data": "AvgDaysH1" ,
   	                       "render": function(obj, type, full) {
   	                    	   		var avgDaysH = full.AvgDaysH?full.AvgDaysH:0;
   	                    	   		return "<input id='"+full.depGroupCode+"_AvgDaysH' type='text' style='width:50px' value='"+avgDaysH+"'></input>";
	  	                         }
 	                     },
 	                     { "data": "AvgFeeL1" ,
 	                       "render": function(obj, type, full) {
 	                    	   var avgFeeL = full.AvgFeeL?full.AvgFeeL:0;
 	                    	   return "<input id='"+full.depGroupCode+"_AvgFeeL' type='text' style='width:50px' value='"+avgFeeL+"'></input>";
  	                         }
   	                     },
  	                     { "data": "AvgFeeH1" ,
  	                       "render": function(obj, type, full) {
  	                    	   		var avgFeeH = full.AvgFeeH?full.AvgFeeH:0;
  	                    	   		return "<input id='"+full.depGroupCode+"_AvgFeeH' type='text' style='width:50px' value='"+avgFeeH+"'></input>";
  	                         	}
	                     },
	                     { "data": "HCAvgFeeL1",
 	                       "render": function(obj, type, full) {
 	                    	   	 var hcAavgFeeL = full.HCAvgFeeL?full.HCAvgFeeL:0;
  	                             return "<input id='"+full.depGroupCode+"_HCAvgFeeL' type='text' style='width:50px' value='"+hcAavgFeeL+"'></input>";
  	                         }
   	                     },
 	                     { "data": "HCAvgFeeH1" ,
   	                       "render": function(obj, type, full) {
   	                    	   		var hcAavgFeeH = full.HCAvgFeeH?full.HCAvgFeeH:0;
   	                    	   		return "<input id='"+full.depGroupCode+"_HCAvgFeeH' type='text' style='width:50px' value='"+hcAavgFeeH+"'></input>";
	  	                         }
 	                     },
 	                     { "data": "DrugFeeL1" ,
 	                       "render": function(obj, type, full) {
 	                    	   var drugFeeL = full.DrugFeeL?full.DrugFeeL:0;
 	                    	   return "<input id='"+full.depGroupCode+"_DrugFeeL' type='text' style='width:50px' value='"+drugFeeL+"'></input>";
  	                         }
   	                     },
  	                     { "data": "DrugFeeH1" ,
  	                       "render": function(obj, type, full) {
  	                    	   		var drugFeeH = full.DrugFeeH?full.DrugFeeH:0;
  	                    	   		return "<input id='"+full.depGroupCode+"_DrugFeeH' type='text' style='width:50px' value='"+drugFeeH+"'></input>";
  	                         	}
	                     },
	                     { "data": "HCDrugFeeL1" ,
 	                       "render": function(obj, type, full) {
 	                    	   var hcDrugFeeL = full.HCDrugFeeL?full.HCDrugFeeL:0;
 	                    	   return "<input id='"+full.depGroupCode+"_HCDrugFeeL' type='text' style='width:50px' value='"+hcDrugFeeL+"'></input>";
  	                         }
   	                     },
  	                     { "data": "HCDrugFeeH1" ,
  	                       "render": function(obj, type, full) {
  	                    	   		var hcDrugFeeH = full.HCDrugFeeH?full.HCDrugFeeH:0;
  	                    	   		return "<input id='"+full.depGroupCode+"_HCDrugFeeH' type='text' style='width:50px' value='"+hcDrugFeeH+"'></input>";
  	                         	}
	                     },
	                     { "data": "DrugMateFeeL1" ,
 	                       "render": function(obj, type, full) {
 	                    	   var drugMateFeeL = full.DrugMateFeeL?full.DrugMateFeeL:0;
 	                    	   return "<input id='"+full.depGroupCode+"_DrugMateFeeL' type='text' style='width:50px' value='"+drugMateFeeL+"'></input>";
  	                         }
   	                     },
	                     { "data": "DrugMateFeeH2" ,
  	                       "render": function(obj, type, full) {
  	                    	   		var drugMateFeeH = full.DrugMateFeeH?full.DrugMateFeeH:0;
  	                    	   		return "<input id='"+full.depGroupCode+"_DrugMateFeeH' type='text' style='width:50px' value='"+drugMateFeeH+"'></input>";
  	                         	}
	                     },
	                     { "data": "HCDrugMateFeeL1" ,
 	                       "render": function(obj, type, full) {
 	                    	   var hcDrugMateFeeL = full.HCDrugMateFeeL?full.HCDrugMateFeeL:0;
 	                    	   return "<input id='"+full.depGroupCode+"_HCDrugMateFeeL' type='text' style='width:50px' value='"+hcDrugMateFeeL+"'></input>";
  	                         }
   	                     },
	                     { "data": "HCDrugMateFeeH2" ,
  	                       "render": function(obj, type, full) {
  	                    	   		var hcDrugMateFeeH = full.HCDrugMateFeeH?full.HCDrugMateFeeH:0;
  	                    	   		return "<input id='"+full.depGroupCode+"_HCDrugMateFeeH' type='text' style='width:50px' value='"+hcDrugMateFeeH+"'></input>";
  	                         	}
	                     }
	                 ];
			

		var paramDatatable = {
				lengthChange : false,
				info : false,
				searching : false,
				order : [ [ 1, "desc" ] ],
				paging : false,
				scrollX:false,
				scrollY:320
		};
		if(qouta_roles!="医保"){
			paramDatatable.columnDefs=[{
				 "visible": false,
				  "targets": [6,7,10,11,14,15]
	         }]
		}
			paramTable = $("#"+tabId+" #paramDepGroup-table").dataTableBasic(columns, result.data, paramDatatable);
		});
	})
	$("#"+tabId+" #search_png").click();
	
	//批量修改事件
	$("#"+tabId+" #mergeParamOk").click(function(){
		$("#paramDepGroup-table tbody").find("tr").each(function(i, n){
			if(qouta_roles=="医政"){
				if($("#"+tabId+" #paramQuotaCheck").val()=="AvgDays"){
					if($("#"+tabId+" input[name='checkAll']:checked").val()==1 || ($("#"+tabId+" input[name='checkAll']:checked").val()==0 && $(n).find("td").eq(0).find("input[type='checkbox']").is(':checked'))){
						$(n).find("td").eq(2).find("input").attr("value",$("#"+tabId+" #overManageID").val());
						$(n).find("td").eq(3).find("input").attr("value",$("#"+tabId+" #notOverManageID").val());
					}
				}
				if($("#"+tabId+" #paramQuotaCheck").val()=="AvgFee"){
					if($("#"+tabId+" input[name='checkAll']:checked").val()==1 || ($("#"+tabId+" input[name='checkAll']:checked").val()==0 && $(n).find("td").eq(0).find("input[type='checkbox']").is(':checked'))){
						$(n).find("td").eq(4).find("input").attr("value",$("#"+tabId+" #overManageID").val());
						$(n).find("td").eq(5).find("input").attr("value",$("#"+tabId+" #notOverManageID").val());
					}
				}
				if($("#"+tabId+" #paramQuotaCheck").val()=="DrugFee"){
					if($("#"+tabId+" input[name='checkAll']:checked").val()==1 || ($("#"+tabId+" input[name='checkAll']:checked").val()==0 && $(n).find("td").eq(0).find("input[type='checkbox']").is(':checked'))){
						$(n).find("td").eq(6).find("input").attr("value",$("#"+tabId+" #overManageID").val());
						$(n).find("td").eq(7).find("input").attr("value",$("#"+tabId+" #notOverManageID").val());
					}
				}

				if($("#"+tabId+" #paramQuotaCheck").val()=="DrugMateFee"){
					if($("#"+tabId+" input[name='checkAll']:checked").val()==1 || ($("#"+tabId+" input[name='checkAll']:checked").val()==0 && $(n).find("td").eq(0).find("input[type='checkbox']").is(':checked'))){
						$(n).find("td").eq(8).find("input").attr("value",$("#"+tabId+" #overManageID").val());
						$(n).find("td").eq(9).find("input").attr("value",$("#"+tabId+" #notOverManageID").val());
					}
				}
			}else{
				if($("#"+tabId+" #paramQuotaCheck").val()=="AvgDays"){
					if($("#"+tabId+" input[name='checkAll']:checked").val()==1 || ($("#"+tabId+" input[name='checkAll']:checked").val()==0 && $(n).find("td").eq(0).find("input[type='checkbox']").is(':checked'))){	
						$(n).find("td").eq(2).find("input").attr("value",$("#"+tabId+" #overManageID").val());
						$(n).find("td").eq(3).find("input").attr("value",$("#"+tabId+" #notOverManageID").val());
					}
				}
				if($("#"+tabId+" #paramQuotaCheck").val()=="AvgFee"){
					if($("#"+tabId+" input[name='checkAll']:checked").val()==1 || ($("#"+tabId+" input[name='checkAll']:checked").val()==0 && $(n).find("td").eq(0).find("input[type='checkbox']").is(':checked'))){
						$(n).find("td").eq(4).find("input").attr("value",$("#"+tabId+" #overManageID").val());
						$(n).find("td").eq(5).find("input").attr("value",$("#"+tabId+" #notOverManageID").val());
					}
				}
				if($("#"+tabId+" #paramQuotaCheck").val()=="HCAvgFee"){
					if($("#"+tabId+" input[name='checkAll']:checked").val()==1 || ($("#"+tabId+" input[name='checkAll']:checked").val()==0 && $(n).find("td").eq(0).find("input[type='checkbox']").is(':checked'))){
						$(n).find("td").eq(6).find("input").attr("value",$("#"+tabId+" #overManageID").val());
						$(n).find("td").eq(7).find("input").attr("value",$("#"+tabId+" #notOverManageID").val());
					}
				}
				if($("#"+tabId+" #paramQuotaCheck").val()=="DrugFee"){
					if($("#"+tabId+" input[name='checkAll']:checked").val()==1 || ($("#"+tabId+" input[name='checkAll']:checked").val()==0 && $(n).find("td").eq(0).find("input[type='checkbox']").is(':checked'))){
						$(n).find("td").eq(8).find("input").attr("value",$("#"+tabId+" #overManageID").val());
						$(n).find("td").eq(9).find("input").attr("value",$("#"+tabId+" #notOverManageID").val());
					}
				}
				if($("#"+tabId+" #paramQuotaCheck").val()=="HCDrugFee"){
					if($("#"+tabId+" input[name='checkAll']:checked").val()==1 || ($("#"+tabId+" input[name='checkAll']:checked").val()==0 && $(n).find("td").eq(0).find("input[type='checkbox']").is(':checked'))){
						$(n).find("td").eq(10).find("input").attr("value",$("#"+tabId+" #overManageID").val());
						$(n).find("td").eq(11).find("input").attr("value",$("#"+tabId+" #notOverManageID").val());
					}
				}
				if($("#"+tabId+" #paramQuotaCheck").val()=="DrugMateFee"){
					if($("#"+tabId+" input[name='checkAll']:checked").val()==1 || ($("#"+tabId+" input[name='checkAll']:checked").val()==0 && $(n).find("td").eq(0).find("input[type='checkbox']").is(':checked'))){
						$(n).find("td").eq(12).find("input").attr("value",$("#"+tabId+" #overManageID").val());
						$(n).find("td").eq(13).find("input").attr("value",$("#"+tabId+" #notOverManageID").val());
					}
				}
				if($("#"+tabId+" #paramQuotaCheck").val()=="HCDrugMateFee"){
					if($("#"+tabId+" input[name='checkAll']:checked").val()==1 || ($("#"+tabId+" input[name='checkAll']:checked").val()==0 && $(n).find("td").eq(0).find("input[type='checkbox']").is(':checked'))){
						$(n).find("td").eq(14).find("input").attr("value",$("#"+tabId+" #overManageID").val());
						$(n).find("td").eq(15).find("input").attr("value",$("#"+tabId+" #notOverManageID").val());
					}
				}
			}
		})
	})
	//开始测算
	$("#"+tabId+" #calculate_btn").click(function(){
		var dateFrom = $("#"+tabId+" #sdate").val();
		var dateTo = $("#"+tabId+" #edate").val();
		
		$("#calculate_btn").attr("disabled", "");
		$("#calculate_btn").html("正在测算");
		$('#total1').html('0%');
		$('#total1').css('width','0%');
		$("#processInfo").html("正在保存参数");
		$('#processId').fadeIn(500);
		var str = "";
		var rows = paramTable.columns().context[0].aoData;
		$.each(rows, function(i, n){
			
			n=n.anCells;
			var depGroupCode=$(n[2]).find("input").attr("id")?$(n[2]).find("input").attr("id").split("_")[0]:"";
			str += depGroupCode+"|";
			if(qouta_roles=="医政"){
				var avgDaysL=$(n[2]).find("input").val();
				var avgDaysH=$(n[3]).find("input").val();
				str += "AvgDays:"+avgDaysL+":"+avgDaysH;
				str += "-";
				var avgFeeL=$(n[4]).find("input").val();
				var avgFeeH=$(n[5]).find("input").val();
				str += "AvgFee:"+avgFeeL+":"+avgFeeH;
				str += "-";
				var drugFeeL=$(n[8]).find("input").val();
				var drugFeeH=$(n[9]).find("input").val();
				str += "DrugFee:"+drugFeeL+":"+drugFeeH;
				str += "-";
				var drugMateFeeL=$(n[12]).find("input").val();
				var drugMateFeeH=$(n[13]).find("input").val();
				str += "DrugMateFee:"+drugMateFeeL+":"+drugMateFeeH;
			}else{
				var avgDaysL=$(n[2]).find("input").val();
				var avgDaysH=$(n[3]).find("input").val();
				str += "AvgDays:"+avgDaysL+":"+avgDaysH;
				str += "-";
				var avgFeeL=$(n[4]).find("input").val();
				var avgFeeH=$(n[5]).find("input").val();
				str += "AvgFee:"+avgFeeL+":"+avgFeeH;
				str += "-";
				var hcavgFeeL=$(n[6]).find("input").val();
				var hcavgFeeH=$(n[7]).find("input").val();
				str += "HCAvgFee:"+hcavgFeeL+":"+hcavgFeeH;
				str += "-";
				var drugFeeL=$(n[8]).find("input").val();
				var drugFeeH=$(n[9]).find("input").val();
				str += "DrugFee:"+drugFeeL+":"+drugFeeH;
				str += "-";
				var hcdrugFeeL=$(n[10]).find("input").val();
				var hcdrugFeeH=$(n[11]).find("input").val();
				str += "HCDrugFee:"+hcdrugFeeL+":"+hcdrugFeeH;
				str += "-";
				var drugMateFeeL=$(n[12]).find("input").val();
				var drugMateFeeH=$(n[13]).find("input").val();
				str += "DrugMateFee:"+drugMateFeeL+":"+drugMateFeeH;
				str += "-";
				var hcdrugMateFeeL=$(n[14]).find("input").val();
				var hcdrugMateFeeH=$(n[15]).find("input").val();
				str += "HCDrugMateFee:"+hcdrugMateFeeL+":"+hcdrugMateFeeH;
			}
			str += ",";
		})
		str = str.substr(0, str.length-1)
		
		//测算方法关键代码, 见后台
		$.post(contextPath+"/ForeCast/saveParamData.dhc", {'type1': str, 'dateFrom':dateFrom, 'dateTo':dateTo, 'type3': planYear,'roleName':qouta_roles})
		.done(function(result){
			var data = result.data;
			var dataDep = data.dep;
			var dataDepGroup = data.depGroup;
			var dataHosp = data.hosp;
			
			loadResultTableHosp(dataHosp);
			loadResultTableDepGroup(dataDepGroup);
			loadResultTableDep(dataDep);
		});
		//进度条
		var timerId = window.setInterval(function(){
			$.post(contextPath+"/ForeCast/getProcess.dhc")
			.done(function(result){
				var data = result.data;
				if(data){
					var total = data.total;
					var current = data.currentDepCount?data.currentDepCount:0;
					var percent11 = (parseFloat(current)/parseFloat(total))*98;
					var currentDepName = data.currentDepName?data.currentDepName:"";
					$('#total1').html(percent11.toFixed(0)+'%');
					$('#total1').css('width',percent11+'%');
					$("#processInfo").html(currentDepName);
					if(data.states=="dis"){
						$("#processInfo").html("正在汇总病种数据...");
					}
					if(data.states=="success"){
						$('#total1').html('100%');
						$('#total1').css('width','100%');
						window.clearInterval(timerId);
						$("#processInfo").html("测算完成");
						$('#processId').fadeOut("slow");
						$("#calculate_btn").removeAttr("disabled");
						$("#calculate_btn").html("开始测算");
			        }
				}
			});
		}, 1000);
	})
	//保存为绩效标杆
	$("#"+tabId+" #saveHosp_manager_btn").click(function(){
		$.post(contextPath+"/ForeCast/saveToQuotamanage.dhc",{
			stdType:'hosp',
			saveType:"I",
			planYear:$('#'+tabId+' #planYear').val()
		}).done(function(result){
			if(result.success){
				drgUI.success("成功保存为绩效标杆！");
			}else{
				drgUI.error("保存为绩效标杆失败！");
			}
		})
	});
	
	$("#"+tabId+" #saveDepGroup_manager_btn").click(function(){
		$.post(contextPath+"/ForeCast/saveToQuotamanage.dhc",{
			stdType:"depGroup",
			saveType:"I",
			planYear:$('#'+tabId+' #planYear').val()
		}).done(function(result){
			if(result.success){
				drgUI.success("成功保存为绩效标杆！");
			}else{
				drgUI.error("保存为绩效标杆失败！");
			}
		})
	});
	$("#"+tabId+" #saveDep_manager_btn").click(function(){
		$.post(contextPath+"/ForeCast/saveToQuotamanage.dhc",{
			stdType:"dep",
			saveType:"I",
			planYear:$('#'+tabId+' #planYear').val()
		}).done(function(result){
			if(result.success){
				drgUI.success("成功保存为绩效标杆！");
			}else{
				drgUI.error("保存为绩效标杆失败！");
			}
		})
	});
})
//跳转科室参数设置页面
function goToDepParam(depGroupCode, depGroupDesc){
	var str = "";
	$("#"+tabId+" #paramDepGroup-table tbody").find("tr").each(function(i, n){
		var depGroupCodes=$(n).find("td").eq(2).find("input").attr("id")?$(n).find("td").eq(2).find("input").attr("id").split("_")[0]:"";
		if(depGroupCodes==depGroupCode){
			var avgDaysL=$(n).find("td").eq(2).find("input").val();
			var avgDaysH=$(n).find("td").eq(3).find("input").val();
			str += "AvgDays:"+avgDaysL+":"+avgDaysH;
			str += "-";
			var avgFeeL=$(n).find("td").eq(4).find("input").val();
			var avgFeeH=$(n).find("td").eq(5).find("input").val();
			str += "AvgFee:"+avgFeeL+":"+avgFeeH;
			str += "-";
			var hcavgFeeL=$(n).find("td").eq(6).find("input").val();
			var hcavgFeeH=$(n).find("td").eq(7).find("input").val();
			str += "HCAvgFee:"+hcavgFeeL+":"+hcavgFeeH;
			str += "-";
			var drugFeeL=$(n).find("td").eq(8).find("input").val();
			var drugFeeH=$(n).find("td").eq(9).find("input").val();
			str += "DrugFee:"+drugFeeL+":"+drugFeeH;
			str += "-";
			var hcdrugFeeL=$(n).find("td").eq(10).find("input").val();
			var hcdrugFeeH=$(n).find("td").eq(11).find("input").val();
			str += "HCDrugFee:"+hcdrugFeeL+":"+hcdrugFeeH;
			str += ",";
		}
	})
	str = str.substr(0, str.length-1)
	openTab('/pages/forecast/forecastDep.jsp', depGroupDesc+"|科室参数配置", 'forecastParamDep'+depGroupCode, 'forecastParamDep'+depGroupCode, {depGroupCode:depGroupCode, param:str, dateFrom: $("#"+tabId+" #sdate").val(), dateTo: $("#"+tabId+" #edate").val()});
}
//跳转科室组病组参数设置,暂时先不执行,后续增加
function goToDepGroupDisParam(depGroupCode){
	var str = "";
	$("#"+tabId+" #paramDepGroup-table tbody").find("tr").each(function(i, n){
		var depGroupCodes=$(n).find("td").eq(2).find("input").attr("id")?$(n).find("td").eq(2).find("input").attr("id").split("_")[0]:"";
		if(depGroupCodes==depGroupCode){
			var avgDaysL=$(n).find("td").eq(2).find("input").val();
			var avgDaysH=$(n).find("td").eq(3).find("input").val();
			str += "AvgDays:"+avgDaysL+":"+avgDaysH;
			str += "-";
			var avgFeeL=$(n).find("td").eq(4).find("input").val();
			var avgFeeH=$(n).find("td").eq(5).find("input").val();
			str += "AvgFee:"+avgFeeL+":"+avgFeeH;
			str += "-";
			var hcavgFeeL=$(n).find("td").eq(6).find("input").val();
			var hcavgFeeH=$(n).find("td").eq(7).find("input").val();
			str += "HCAvgFee:"+hcavgFeeL+":"+hcavgFeeH;
			str += "-";
			var drugFeeL=$(n).find("td").eq(8).find("input").val();
			var drugFeeH=$(n).find("td").eq(9).find("input").val();
			str += "DrugFee:"+drugFeeL+":"+drugFeeH;
			str += "-";
			var hcdrugFeeL=$(n).find("td").eq(10).find("input").val();
			var hcdrugFeeH=$(n).find("td").eq(11).find("input").val();
			str += "HCDrugFee:"+hcdrugFeeL+":"+hcdrugFeeH;
			str += "-";
			var drugMateFeeL=$(n).find("td").eq(12).find("input").val();
			var drugMateFeeH=$(n).find("td").eq(13).find("input").val();
			str += "DrugMateFee:"+drugMateFeeL+":"+drugMateFeeH;
			str += "-";
			var hcdrugMateFeeL=$(n).find("td").eq(14).find("input").val();
			var hcdrugMateFeeH=$(n).find("td").eq(15).find("input").val();
			str += "HCDrugMateFee:"+hcdrugMateFeeL+":"+hcdrugMateFeeH;
			str += ",";
		}
	})
	str = str.substr(0, str.length-1)
	openTab('/pages/forecast/forecastDepGroupDis.jsp', depGroupCode+"|病种参数配置", 'forecastParamDis'+depGroupCode, 'forecastParamDis'+depGroupCode, {depGroupCode:depGroupCode, param:str});
}
//选择理想值、预测值 事件
function queryBytype(){
	var dateFrom = $("#"+tabId+" #sdate").val();
	var dateTo = $("#"+tabId+" #edate").val();
	
    //后台获取数据并加载
		$.post(contextPath+"/ForeCast/getLastResultHosp.dhc", {saveType: "I",stdYear:planYear})
		.done(function(result){
			var data = result.data;
			if(data){
				loadResultTableHosp(data);
			}else{
				emptyResultTableHosp();//清空全院数据	
			}
		});
		$.post(contextPath+"/ForeCast/getLastResultDepGroup.dhc", {saveType: "I",stdYear:planYear})
		.done(function(result){
			var data = result.data;
			if(data){
				loadResultTableDepGroup(data);
			}else{
				emptyResultTable();//清空科室组数据	

			}
		});	
		//获取科室上次预测的数据
		$.post(contextPath+"/ForeCast/getLastResultDep.dhc", {saveType: "I",stdYear:planYear})
		.done(function(result){
			var data = result.data;
			if(data){
				loadResultTableDep(data);
			}
		});
		
	}
